home *** CD-ROM | disk | FTP | other *** search
- Path: unix.sri.com!usenet
- From: mklenk@updike.sri.com (Mark Klenk)
- Newsgroups: comp.lang.c
- Subject: Re: Help on Dynamically Allocating an Array?
- Date: 9 Jan 1996 22:53:52 GMT
- Organization: SRI International
- Message-ID: <4curm0$t65@unix.sri.com>
- References: <4cq273$aeq@mercury.IntNet.net>
- Reply-To: mklenk@updike.sri.com
- NNTP-Posting-Host: 204.75.161.40
-
-
- >I'm confused on who to dynamically allocate an array of any type. Any
- >help would be much appreciated.
-
- #include <stdlib.h>
-
- #define NEW(type, num) \
- ((type *)malloc(sizeof(type) * (num)))
-
- typedef struct {
- double real, imag;
- } Complex;
-
- Complex * ComplexVectorAdd(Complex const * one, Complex const * two,
- int vector_size)
- {
- Complex * result = NEW(Complex, vector_size);
-
- if (NULL != result) {
- int i;
- for (i = 0; i < vector_size; ++i) {
- result[i].real = one[i].real + two[i].real;
- result[i].imag = one[i].imag + two[i].imag;
- }
- }
-
- return result;
- }
-
- ---
-
- mklenk@coronacorp.com (Mark Klenk)
-
-
-
-